package demo4.service;

import demo4.DAO.IUserDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserService implements IUserService{
    @Autowired
    private IUserDAO userDAO;
    @Override
    public boolean doLogin(String username, String password) {
        System.out.println("UserService:根据用户名查询用户信息...");
        Boolean result = userDAO.findUserByName(username);
        if(result){
            System.out.println("UserService:比对密码是否正确");
            if(Math.random() > 0.5){
                System.out.println("UserService:登录成功");
                return true;
            }else {
                System.out.println("UserService:登录失败");
                return false;
            }
        }else{
            System.out.println("UserService:用户名不存在");
        }
        return false;
    }
}
